<!doctype html>
<html lang="en">
  <head>
    <title>Test form</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <script type="text/javascript" src="webtoolkit.sha1.js"></script>
    <script type="text/javascript">
      function trim (lines) {
        lines = lines.split('\n');
        for (var l=0; l<lines.length; l++) {
          var str = lines[l];
          str.replace(/\r/g,'');
          str = str.replace(/^\s\s*/, '');
          var ws = /\s/, i = str.length;
          while (ws.test(str.charAt(--i)));
          str = str.slice(0, i + 1);
          lines[l] = str;
        }
        return lines.join('');
      }
      function calcHash() {
        document.getElementById('result').contentWindow.document.body.innerHTML = '...';
        var domain = 'localhost'; //same as in configuration on server side
        var key = '21:38_72h3n*%xh218wdxuw+xhd8uxh82husdx#$hn8uhdxn21'; //same as in configuration on server side
        var data = document.getElementById('nicedata').value;
        data = trim(data);
        document.getElementById('data').value = trim(data)
        //calculate checksum
        var cksum = SHA1(domain+data+key);
        document.getElementById('hash').value = cksum;
        updateClientTime();
        return true;
      };
      function updateClientTime() {
        document.getElementById('clientTime').value = new Date().getTime();
      }
      function load() {
        calcHash();
        setInterval(updateClientTime,1000);
      }
    </script>
  </head>
  <body onload="load()">
    <h1>Test form</h1>
    <p>if you will see 0 after submit there was error, if you will see 1 data were stored successfully on server</p>
    <form action="/save" target="result" method="post" onsubmit="calcHash()">
      ClientTime (milisecconds from EPOCH): <input type="text" name="clientTime" id="clientTime" value=""/><br/>
      Hash: <input type="text" name="hash" id="hash" value=""/> <a href="#" onclick="calcHash()">Recalculate Hash</a><br/>
      Data:<br/>
      <textarea id="nicedata" rows="15" cols="40">{
  "items": [
    {
      "group": "request",
      "type": "page",
      "loadtime": "10ms"
    }
  ]
}</textarea><br/>
      <input type="hidden" id="data" name="data" value=""/>
      <input type="submit" value="Calculate Hash & Send" /><br />
    </form>
    <br />
    <hr />
    Result:<br />
    <iframe width="300" height="100" id="result" name="result">...</iframe>
    
  </body>
</html>